﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace SRAGWMCLib.OO
{
    /// <summary>
    /// Contains the details of the Features and Map 
    /// </summary>
    /// 

    public class LegendEntry
    {
        /// <summary>
        /// Allows to show/hide any controller
        /// </summary>
        public bool Visible { get; set; }

        /// <summary>
        /// Style of the Features and Map
        /// </summary>
        
        public int SymbologyStyle { get; set;}
       
        /// <summary>
        /// Weight of the Features and Map
        /// </summary>
        
        public int SymbologyWeight { get; set;}
        
        /// <summary>
        /// Tooltip to be shown
        /// </summary>

        public string Tooltip { get; set;}

        /// <summary>
        /// Map and Features fill color 
        /// </summary>

        public Color FillColor { get; set;}

        /// <summary>
        /// Map and Featutes border color
        /// </summary>

        public Color BorderColor { get; set;}

        /// <summary>
        /// Property of the Filter Class
        /// </summary>

        public Filter Filter { get; set;}

        /// <summary>
        /// Property of the DataSource Class
        /// </summary>

        public DataSource DataSource { get; set;}

        /// <summary>
        /// Fills the necessary data into the Legend Entry
        /// </summary>
        /// <param name="pSymbologyStyle">Sets the Style of the symbology to be displayed</param>
        /// <param name="pSymbologyWeight">Sets the Weight of the symbology to be displayed</param>
        /// <param name="pBorderColor">Defines the color to fill the Map and it's features</param>
        /// <param name="pFillColor">Defines the color to fill the Map and it's features</param>
        /// <param name="pTooltip">Sets the table fields as a tooltip to be shown</param>
        /// 

        public LegendEntry(int pSymbologyStyle, int pSymbologyWeight, 
            Color pBorderColor, Color pFillColor, string pTooltip) 
        {
            SymbologyStyle = pSymbologyStyle;
            SymbologyWeight = pSymbologyWeight;
            FillColor = pFillColor;
            BorderColor = pBorderColor;
            Tooltip = pTooltip;
            //Show = pShow;
        }

        /// <summary>
        /// Fills the DataSource
        /// </summary>
        /// <param name="pDBName">Name desired for the connection </param>
        /// <param name="pDBConnectionName">Name of the database previusly set in the DataBase property</param>
        /// <param name="pTableName">Desired Table to be used</param>
        /// <param name="pTableFields">Desired Fields to be presented as tooltip</param>
        /// 

        public void SetDataSource(string pDBMarkerName, string pDBConnectionName, string pTableName, string[] pTableFields)
        {
            DataSource DS = new DataSource(pDBMarkerName, pDBConnectionName, pTableName, pTableFields);

            DataSource = DS;
        }

        /// <summary>
        /// Fills the Filter
        /// </summary>
        /// <param name="pWhereClause">If a where clause is to be used it is added here, if not, this property is set as ""</param>
        /// <param name="pPoints">Points of coordinates in pairs of X,Y</param>
        /// <param name="pNumPairs">Number of pairs of points</param>
        /// <param name="pSpatialOperator">Operator that defines whether or not the features touch the geometry (normally set as 4)</param>
        /// 

        public void SetFilter(string pWhereClause, object[] pPoints, int pNumPairs, int pSpatialOperator)
        {
            Filter F = new Filter(pWhereClause, pPoints, pNumPairs, pSpatialOperator);

            Filter = F;
        }

        /// <summary>
        /// Fills the values for the feature and mapdisplay
        /// </summary>
        /// <param name="Atributes">The field of the DataBase to fill the tooltip afterwards</param>
        /// <param name="Tooltip">The tooltip to show</param>
        /// <param name="SymbologyStyle">The style of the border</param>
        /// <param name="SymbologyWeight">The weight of the border</param>
        /// <param name="BorderColor">Color od the border of the map</param>
        /// <param name="FillColor">Color to fill the map</param>
        /// <param name="DBName">Data Base Name</param>
        /// <param name="TableName">The Name of the Table from the DataBase</param>
        /// <param name="Pnts">Points of the Poligon</param>
        /// <param name="NumPairs">Number of Pairs of Points</param>
        /// <param name="SpatialOperator">How the features are to be displayed</param>
        /// <param name="MarkerName">Name of the Marker</param>
        /// <returns>Returns the le</returns>
        /// 

        public static LegendEntry LegendEntryBuilder(string[] Atributes, string Tooltip, int SymbologyStyle, int SymbologyWeight,
                                        Color BorderColor, Color FillColor, string DBConnectionName, string TableName,
                                        object[] Pnts, int NumPairs, int SpatialOperator, string DBMarkerName, Boolean Visible)
        {
            LegendEntry le = new LegendEntry(SymbologyStyle, SymbologyWeight, BorderColor, FillColor, Tooltip);
            le.SetDataSource(DBMarkerName, DBConnectionName, TableName, Atributes);
            le.SetFilter("", Pnts, NumPairs, SpatialOperator);
            le.Visible = Visible;
            return le;
        }
    }
}
